# _*_ coding: UTF-8 _*_
# @Time     :2023-11-1 17:23
# @Author   :Yunlian Zeng
# @File     :01_get_post.py
import requests

#get请求
# r = requests.get('http://localhost/smeoa/login/index')
# print(r.cookies)
# print(r.headers['Set-Cookie'],r.status_code)
# # print(r.text)
# if '小微企业信息化' in r.text:
#     print('访问首页成功')
# else:
#     print('访问首页失败')

#post请求
# datas = {'emp_no':'admin','password':'admin'}
# r = requests.post('http://localhost/smeoa/login/check_login', data=datas)
# # print(r.text)
# print(r.cookies)
# if '退出' in r.text:
#     print('登陆成功')
# else:
#     print('登陆失败')
#
# r = requests.get('http://localhost/smeoa/task/folder/fid/all')
# print(r.text)

# #session
datas = {'emp_no':'admin','password':'admin'}
s = requests.Session()
r = s.post('http://localhost/smeoa/login/check_login', data=datas)
# print(r.text)
print(r.cookies)
if '退出' in r.text:
    print('登陆成功')
else:
    print('登陆失败')

r = s.get('http://localhost/smeoa/task/folder/fid/all')
print(r.text)

#添加公告
# headers = {'Content-Type': 'application/x-www-form-urlencoded'}
# url = 'http://localhost/smeoa/notice_folder/save'
# data = 'id=&opmode=add&admin=%E6%80%BB%E7%BB%8F%E7%90%861001%2F%E6%80%BB%E7%BB%8F%E7%90%86%7C1001%3B%E6%80%BB%E7%9B%912001%2F%E6%80%BB%E7%9B%91%7C2001%3B&write=%E6%80%BB%E7%9B%912001%2F%E6%80%BB%E7%9B%91%7C2001%3B&read=%E6%80%BB%E7%9B%912001%2F%E6%80%BB%E7%9B%91%7C2001%3B&folder_list=0&name=1117-1348&folder_name=%E5%AD%A6%E6%A0%A1&pid=69&sort=1&is_del=0&remark=%E5%A4%87%E6%B3%A8'
# r = s.post(url, data = data, headers=headers)
# print(r.text)

#添加日报
headers = {'content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryAssjIGTSY2lqZzyl'}
url = 'http://localhost/smeoa/task/save'
data = {"ajax":'0',
"add_file": ("file.txt", open("demo_smeoa.txt", "rb"), "text/plain"),
"executor":'总经理1001|44',
"opmode":'add',
"name":'1117-1415',
"expected_time":'2023-11-18 14:00',
"content":'任务说明'}
r = s.post(url, data=data, headers=headers)
print(r.text)


# r = requests.get('https://kyfw.12306.cn/otn')
# print(r.text)

#重定向.
#allow_redirects=False,不重定向
# datas = {'emp_no':'admin','password':'admin'}
# r = requests.post('http://localhost/smeoa/login/check_login', data=datas, allow_redirects=False)
# # print(r.text)
# print(r.cookies)
# if '退出' in r.text:
#     print('登陆成功')
# else:
#     print('登陆失败')
